//
//  SettingViewController.swift
//  EasyDana
//
//  Created by mac on 2024/10/18.
//

import UIKit
import RxSwift
import RxCocoa
class SettingViewController: UIViewController {
    let bag = DisposeBag()
    @IBOutlet weak var naviBar: NavigationBar!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.naviBar.title = "Settings".locale
        self.naviBar.backClicked.subscribe(onNext: { [weak self] in
            self?.navigationController?.popViewController(animated: true)
        })
        .disposed(by: self.bag)
        // Do any additional setup after loading the view.
    }
    
    @IBAction func unRegistAction(_ sender: Any) {
        let cancelVC = CancellationViewController()
        cancelVC.cancel.subscribe(onNext: { [weak self] cancel in
//            self?.navigationController?.popToRootViewController(animated: false)
//            self?.tabBarController?.selectedIndex = 0
            let rootVC = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateInitialViewController()
            if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
                windowScene.windows.first?.rootViewController = rootVC
            }
        })
        .disposed(by: self.bag)
        self.alert(viewController: cancelVC)
    }
    
    @IBAction func logoutAction(_ sender: Any) {
        let logoutVC = LogoutViewController()
        logoutVC.logout.subscribe(onNext: { [weak self] logout in
            let rootVC = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateInitialViewController()
            if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
                windowScene.windows.first?.rootViewController = rootVC
            }
//            self?.navigationController?.popToRootViewController(animated: false)
//            self?.tabBarController?.selectedViewController = self!.tabBarController!.viewControllers![0]
        })
        .disposed(by: self.bag)
        self.alert(viewController: logoutVC)
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
